<?php

/* Another Release by.. Pexuga Team xDDD.
*
*  Read files stored in TEMPED2K (granted by pexuga-parser-bash-script)
*  and add selected elinks to the Mldonkey running on the machine.
*  V-0.001
*/
include("lib/class.imdb.php");

$file = "TEMPED2K";
//$descrip = fopen($file,"r");



if (isset($_POST['ed2k']))
	{
	$user=$_POST['user'];
	$pass=$_POST['pass'];
	$mlnet_version = 'echo|mldonkey_command version|tail -3|head -1|cut -d " " -f 2|cut -d ":" -f 1|sed "s/\.//g"';
	$version = shell_exec($mlnet_version);	//Use Version to control MLdonkey Release
	//print "<p style='text-align:right;'>MLDonkey version <strong>$mlnet_version</strong></p>\n";  Comment... by Security Buggy :P
	
	
	foreach($_POST['ed2k'] as $value)
		{
		//echo $value;	
		addelinks($value,$user,$pass,$version);
		}
	unset($_POST['ed2k']);
	}
	

function addelinks($value,$user,$pass,$version){
    
    //$user = "notecreasqlovoyaponerXDDDDD";
    //$pass = "cuxicuxicuxixciuxicxucixucu";
    
    if ($version<=276) {
        $cmd = 'mldonkey_command dllink "'.$value.'"';
    } elseif ($version>276) {
        $cmd = 'mldonkey_command -u "'.$user.'" -p "'.$pass.'" "'.$value.'"';
    } else {
        print "Cannot handle elink: unknown mlnet version";
        $cmd = '';
    }
    shell_exec($cmd);
    //echo "<p>$cmd<br/>Link sended.</p>\n";
    
}

function show_elinks($file)
	{
		if (file_exists($file))
			{
			$descrip = fopen($file,"r");
			echo "<form action=\"$_SERVER[PHP_SELF]\" method='post' name='ed2klinks'>";
			echo "<p><strong>Pelis:</strong></p>";
			//echo "<li class='tip' title='Checkbox'>";
			while (!feof($descrip))
				{
				$buffer=fgets($descrip,4096);
				$NOM = eregi_replace("ed2k://\|file\||Spanish.|XviD.|MP3.|AC3.|By.|DVDRIP.|Freak.Team.|\|(.*)","",$buffer);
				$NOMP = eregi_replace(".avi","",$NOM);
				$m = new MediaInfo();
				$info = $m->getMovieInfo($NOMP);

				if ($buffer != '')
					//echo $info['rating'];
					echo "<label class='f_checkbox'><input type='checkbox' name='ed2k[]' value=\"".$buffer."\"/>".$NOMP." R -".$info['rating']."</label>\n";
				}
			echo "<br/><br/>";
			echo "<input type='text' name='user'/> User<br/>";
			echo "<input type='password' name='pass'/> Pass<br/>";
			
			echo "<input type='submit' value='Enviar'/>";
			echo "</form><br/>";
			//echo "</li>";
			}
			
	else
		echo "<br/> Error: ".$file." No encontrado<br/>";
	}

function lastchanged($file) {

  // Set default timezone
  date_default_timezone_set("Europe/Madrid");

  // Change to the name of the file
  $last_changed = filectime("$file");

  // Display the results
  print "Listado de pelis actualizado el <strong>". date("l, dS F, Y @ H:i", $last_changed)."</strong>.";

}
?>
<?php
print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <title>gpdonkey</title>
  <script type="text/javascript" src="js/mootools.js"></script>
  <script type="text/javascript" src="js/moocheck.js"></script>
  <link href="css/style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="wrapper">
		<div id="outer">
			<div id="formwrap">
				<div id="form1">
<h2>
Parte 2 del Script Pexugeitor.
</h2><br/>

<?
show_elinks($file);
?>
</div></div></div></div>

<p><?php lastchanged($file); ?></p>

<div id="footer">
	&copy; 2008 <a href='/'>Pexuga Corp Devel's</a> | <a href='/'> xD</a>
</div>

</body>
</html>
